import { getListApi, setListApi, delListApi, delAllListApi } from '../../api/staff'

const state = {
    list: [],
    idsArr: []
}

const mutations = {
    GET_LIST(state, data) {
        state.list = data
    },
    // 被选中项的id
    GET_IDS(state, ids) {
        state.idsArr = ids
    }
}


const actions = {
    // 获取数据
    async getList({ commit }) {
        const { data } = await getListApi()
        commit('GET_LIST', data)
    },
    // 保存数据
    async setList({}, data) {
        const res = await setListApi(data)
        console.log(res);
    },

    // 删除单条数据
    async delList({}, id) {
        const res = await delListApi({ _id: id })
        console.log(res);
    },

    // 删除多条数据
    async delAllList({}, idsArr) {
        const ids = JSON.stringify(idsArr)
        const res = await delAllListApi({ ids })
        console.log(res);
    },
}


export default {
    namespaced: true,
    state,
    mutations,
    actions
}